package servlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import dao.CommunityDao;
import dao.impl.CommunityDaoImpl;
import entity.Community;
import service.CommunityService;
import service.impl.CommunityServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;


@WebServlet("/CSupdateServlet")
public class CSupdateServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

//        String id=request.getParameter("id");
        String projectname = request.getParameter("projectname");
        String customer = request.getParameter("customer");
        String staff = request.getParameter("staff");
        String servicenum = request.getParameter("servicenum");
//        int comnum =Integer.parseInt(servicenum);
        String info = request.getParameter("info");
        String starttime = request.getParameter("starttime");
        String finishtime = request.getParameter("finishtime");
        String explain = request.getParameter("explain");

        Community community=new Community(projectname,info,customer, staff, servicenum, starttime, finishtime, explain);
        CommunityService communityService=new CommunityServiceImpl();

        PrintWriter printWriter=response.getWriter();
        printWriter.print(new ObjectMapper().writeValueAsString(communityService.saveCommunity(community)));

    }


}

//@WebServlet("/Searchall")
//public class CommunitySServlent extends HttpServlet{
//    public void doGet(HttpServletRequest request, HttpServletResponse response)
//            throws ServletException, IOException {
//        doPost(request, response);
//    }
//    public void doPost(HttpServletRequest request, HttpServletResponse response)
//            throws ServletException, IOException {
//
//        CommunityDao ud = new CommunityDaoImpl();
//        List<Community> communityAll = ud.getAllcommunity();
//        request.setAttribute("communityAll", communityAll);
//        request.getRequestDispatcher("/showall.jsp").forward(request, response);
//    }
//}

